package Model;

import java.io.Serializable;
import java.util.Random;

import Messaging.Notification;
import Messaging.NotificationManager;

/*
 * @author Roch San Buenaventura
 */

public class Dice implements Serializable 
{
	private static final long serialVersionUID = 107;
	private int die1_, die2_;
	private int numInRowDoubles_;
	private Random generator_ = new Random();
	
	public int roll() 
	{
		die1_ = generator_.nextInt(6) + 1;
		die2_ = generator_.nextInt(6) + 1;
		
		if (die1_ != die2_)
			numInRowDoubles_ = 0;
		
		else if (numInRowDoubles_ < 4)
			numInRowDoubles_++;

		else
			numInRowDoubles_ = 1;
		
		NotificationManager.getInstance().notifyObservers(Notification.ROLL_DICE, this);
		
		return die1_ + die2_;
	}

	public int rollDie1() 
	{
		die1_ = generator_.nextInt(6) + 1;
		return die1_;
	}
	
	public int rollDie2() 
	{
		die2_ = generator_.nextInt(6) + 1;
		return die2_;
	}

	public int getDie1() 
	{
		return die1_;
	}
	
	public int getDie2()
	{
		return die2_;
	}
	
	public int getTotalRoll() 
	{
		return die1_ + die2_;
	}
	
	public int getNumInRowDoubles() 
	{
		return numInRowDoubles_;
	}

	public String toString() 
	{
		return "(" + this.getDie1() + ", " + this.getDie2() + ")";
	}
}

